package com.pagepub.core.tag.validator;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;

public class ValidateItems extends FormValidateBasic {
	private static final long serialVersionUID = -2726234321679222824L;

	private String rightimage;

	private String rightwordcolor;

	private String submitvalidate;

	public String getSubmitvalidate() {
		return submitvalidate;
	}

	public void setSubmitvalidate(String submitvalidate) {
		this.submitvalidate = submitvalidate;
	}

	public String getRightwordcolor() {
		return rightwordcolor;
	}

	public void setRightwordcolor(String rightwordcolor) {
		this.rightwordcolor = rightwordcolor;
	}

	public String getRightimage() {
		return rightimage;
	}

	public void setRightimage(String rightimage) {
		this.rightimage = rightimage;
	}

	public int doStartTag() throws JspException {
		JspWriter out = this.pageContext.getOut();

		try {
			out.print(validatechecked());
		} catch (IOException e) {
			// TODO 自动生成 catch 块

			e.printStackTrace();
		}

		return super.doStartTag();
	}

	public StringBuffer validatechecked() {
		StringBuffer str = new StringBuffer();
		String emptyelement = "";
		String pluselement = "";
		if (this.submitvalidate.equalsIgnoreCase("true")) {
			emptyelement = "emptyelement(realname);";
			pluselement = " pluselement(realname);";
		}
		str.append("<script language=\"javascript\">");
		str.append("function Validatechecked(thisid,realname,spanname){");

		str.append("var flag=0;");
		str.append("if(document.getElementById(thisid).checked==false){");
		str.append("	message=\"对不起,必须服从\"+realname+\"！\";");
		str.append("    imgurl=\"<img src=\\\"" + this.getWrongimage()
				+ "\\\"/>\";");
		str.append(" flag=1;");
		str.append("}");
		str.append("if(flag==1){");
		str.append(this.display());
		str.append(pluselement);
		str.append("return false;}");
		str.append("else { ");
		str.append(this.displayempty());
		str.append(emptyelement);
		str.append("return true;}");
		str.append("}");
		str.append("</script>");
		str.append(this.cTrim());
		return str;
	}

}
